import { request } from '@/service/request';

/**
 * 查询项目列表
 */
export function fetchProjectList(params?: Api.Dataplatform.ProjectSearchParams) {
  return request<Api.Dataplatform.ProjectList>({
    url: '/dataplatform/project/list',
    method: 'get',
    params
  });
}

/**
 * 查询所有项目
 */
export function fetchAllProjects(params?: Api.Dataplatform.ProjectSearchParams) {
  return request<Api.Dataplatform.Project[]>({
    url: '/dataplatform/project/listAll',
    method: 'get',
    params
  });
}

/**
 * 获取项目详情
 */
export function fetchProjectDetail(id: number) {
  return request<Api.Dataplatform.Project>({
    url: `/dataplatform/project/${id}`,
    method: 'get'
  });
}

/**
 * 创建项目
 */
export function addProject(data: Api.Dataplatform.ProjectEdit) {
  return request<number>({
    url: '/dataplatform/project',
    method: 'post',
    data
  });
}

/**
 * 更新项目
 */
export function updateProject(data: Api.Dataplatform.ProjectEdit) {
  return request({
    url: '/dataplatform/project',
    method: 'put',
    data
  });
}

/**
 * 删除项目
 */
export function deleteProject(id: number) {
  return request({
    url: `/dataplatform/project/${id}`,
    method: 'delete'
  });
}

/**
 * 归档项目
 */
export function archiveProject(id: number) {
  return request({
    url: `/dataplatform/project/${id}/archive`,
    method: 'put'
  });
}

/**
 * 恢复项目
 */
export function restoreProject(id: number) {
  return request({
    url: `/dataplatform/project/${id}/restore`,
    method: 'put'
  });
}

/**
 * 查询项目成员列表
 */
export function fetchProjectMembers(projectId: number) {
  return request<Api.Dataplatform.ProjectMember[]>({
    url: `/dataplatform/project/${projectId}/members`,
    method: 'get'
  });
}

/**
 * 添加项目成员
 */
export function addProjectMember(data: Api.Dataplatform.ProjectMemberEdit) {
  return request({
    url: '/dataplatform/project/member',
    method: 'post',
    data
  });
}

/**
 * 更新项目成员
 */
export function updateProjectMember(data: Api.Dataplatform.ProjectMemberEdit) {
  return request({
    url: '/dataplatform/project/member',
    method: 'put',
    data
  });
}

/**
 * 删除项目成员
 */
export function deleteProjectMember(id: number) {
  return request({
    url: `/dataplatform/project/member/${id}`,
    method: 'delete'
  });
}

/**
 * 获取项目资源统计
 */
export function fetchProjectStatistics(projectId: number) {
  return request<Api.Dataplatform.ProjectResourceStatistics>({
    url: `/dataplatform/project/${projectId}/statistics`,
    method: 'get'
  });
}
